<script>
layui.use('table', function(){
  var table = layui.table;
  
  	table.render({
	    elem: '#test'
	    ,url:'user/list/'
		,toolbar: '#toolbarDemo'
	    ,cellMinWidth: 60 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	    ,cols: [[
	      	{field:'UserId', title: 'ID', sort: true}
            ,{field:'UserKey', title: '标识'}
	      	,{field:'UserName', title: '用户名'}
			,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
	    ]]
		,page:true
  	});

	//头工具栏事件
  	table.on('toolbar(test)', function(obj){
	    switch(obj.event){
		  case 'add':
			layer.open({
				type:2,
				area: ['800px','500px'],
				offset: 'auto',
				title:'添加',
				content:"user/add"
			});
	      break;
	    };
	});

	//监听行工具事件
  	table.on('tool(test)', function(obj){
	    var data = obj.data;
	    //console.log(obj)
	    if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
			layui.jquery.get("/user/deletedo?userid="+data.UserId);
	        obj.del();
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
			//self.location="user/edit?id="+data.Mid;
			layer.open({
				type:2,
				area: ['800px','500px'],
				offset: 'auto',
				title:'编辑',
				content:"user/edit?userid="+data.UserId
			});
	    }
	  });
	
});

</script>

